package h0825;

import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 求s中最长的回文子串
 * @date 2024/8/25 13:35
 */
public class ThePalindromeString {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(getRes(s));
    }

    private static String getRes(String s) {
        if (s == null || s.length() < 1) return "";
        int start = 0;
        int end = 0;
        for (int i = 0; i < s.length(); i++) {
            //中心扩展法，从中心向两边扩展。
            int len1 = expandAroundCenter(s, i, i); //奇数长度回文
            int len2 = expandAroundCenter(s, i, i + 1); //偶数长度回文
            int len = Math.max(len1, len2);
            if (len > end - start) {
                start = i - (len - 1) / 2;
                end = i + len / 2;
            }
        }
        return s.substring(start, end + 1);
    }

    private static int expandAroundCenter(String s, int i, int j) {
        int L = i;
        int R = j;
        while (L >= 0 && R < s.length() && s.charAt(L) == s.charAt(R)) {
            L--;
            R++;
        }
        return R - L - 1;
    }
}
